using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICP_MS.Plugin.AnalyteDb.Properties;

namespace ICP_MS.Plugin.AnalyteDb;

public class FormAnalyteDB : Form
{
	private string analytePath = null;

	private AnalyteDB db = new AnalyteDB();

	private bool isSaved = false;

	private string currentAtom = "";

	private object currentAtomicbox = null;

	private AtomEventArgs atomEventArgs = null;

	private IList<AnalyteIsotope> selectIsotopes = new List<AnalyteIsotope>();

	private TreeNode polyNode = null;

	private TreeNode matrixNode = null;

	private TreeNode addPolyNode = null;

	private TreeNode addMatrixNode = null;

	private bool hasLoadIons = false;

	private IContainer components = null;

	private TableLayoutPanel tableLayoutPanel1;

	private TableLayoutPanel tableLayoutPanel2;

	private TreeView treeViewIons;

	private DataGridView dgvIsotopes;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn6;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7;

	private MassDisallowedControl massDisallowedControl1;

	private Panel panel1;

	private PeriodicTable periodicTable1;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn8;

	private MenuStrip menuStripAnalyteDB;

	private ToolStripMenuItem fileToolStripMenuItem;

	private ToolStripSeparator toolStripSeparator4;

	private ToolStripMenuItem tsmiSave;

	private ToolStripMenuItem tsmiSaveAs;

	private DataGridViewCheckBoxColumn colSelect;

	private DataGridViewCheckBoxColumn colDefault;

	private DataGridViewTextBoxColumn colSymbol;

	private DataGridViewTextBoxColumn colMass;

	private DataGridViewTextBoxColumn colAbundance;

	private DataGridViewTextBoxColumn colEquation;

	private DataGridViewTextBoxColumn colInterference;

	public event EventHandler updateToolstrip = null;

	public FormAnalyteDB(string analyteDB, bool exist = false)
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		analytePath = analyteDB;
		InitializeComponent();
		ApplyResources();
		InitIonsTree();
		periodicTable1.AtomClick += new DelegateAtomClick(periodicTable_AtomClick);
		isSaved = exist;
		dgvIsotopes.AutoGenerateColumns = false;
		dgvIsotopes.DataSource = selectIsotopes;
	}

	private void ReBindDatas()
	{
		BindingContext[dgvIsotopes.DataSource].SuspendBinding();
		dgvIsotopes.DataSource = null;
		dgvIsotopes.DataSource = selectIsotopes;
		BindingContext[dgvIsotopes.DataSource].ResumeBinding();
	}

	public void periodicTable_AtomClick(object sender, AtomEventArgs e)
	{
		currentAtomicbox = sender;
		atomEventArgs = e;
		currentAtom = e.Atomic;
		AddIsotope2Dgw(currentAtom);
	}

	private void AddIsotope2Dgw(string atom)
	{
		Cursor = Cursors.WaitCursor;
		IList<AnalyteIsotope> isotopes = db.GetAnalyteIsotopesByAtomic(currentAtom);
		if (isotopes != null)
		{
			selectIsotopes = isotopes;
			ReBindDatas();
		}
		Cursor = Cursors.Arrow;
	}

	private string GetEquations(int peakId)
	{
		string equation = "";
		IList<InterferenceEquation> interferences = db.GetInterferenceEquation(peakId);
		foreach (InterferenceEquation interference in interferences)
		{
			double factor = interference.interferenceFactor;
			string symbol = db.GetSymbolById(interference.interferenceId);
			equation = equation + ((factor >= 0.0) ? "+" : "-") + factor.ToString("F5") + " * " + symbol;
		}
		return equation;
	}

	public bool InitDB()
	{
		if (File.Exists(analytePath))
		{
			return db.Init(analytePath);
		}
		return false;
	}

	private bool CloseDB()
	{
		return db.Close();
	}

	private void FormAnalyteDB_FormClosing(object sender, FormClosingEventArgs e)
	{
		SaveDisallowedRanges();
		if (!isSaved)
		{
			switch (MessageBox.Show(Lang.Txt("FormAnalyteDB.MessageBox.Content.Text"), Lang.Txt("FormAnalyteDB.MessageBox.Caption.Text"), MessageBoxButtons.YesNoCancel))
			{
			case DialogResult.Cancel:
				e.Cancel = true;
				break;
			case DialogResult.Yes:
				if (SaveDB() == 0)
				{
					e.Cancel = true;
				}
				break;
			}
		}
		else
		{
			WritetoLocal();
		}
		if (!e.Cancel)
		{
			db.Close();
			if (!isSaved)
			{
				File.Delete(analytePath);
			}
		}
	}

	private void WritetoLocal()
	{
		db.WriteToLocal(analytePath);
	}

	private int SaveDB(bool saveAs = false)
	{
		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Filter = Lang.Txt("FormAnalyteDB.DataBase.Template.Text");
		dlg.FileName = Path.GetFileName(analytePath);
		dlg.Title = dlg.FileName;
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			try
			{
				string fileName = dlg.FileName;
				if (File.Exists(fileName))
				{
					File.Delete(fileName);
				}
				if (!saveAs)
				{
					File.Delete(analytePath);
				}
				analytePath = fileName;
				WritetoLocal();
				Text = Path.GetFileNameWithoutExtension(analytePath);
				if (this.updateToolstrip != null)
				{
					this.updateToolstrip(this, null);
				}
				return 1;
			}
			catch
			{
				return -1;
			}
		}
		return 0;
	}

	private void FormAnalyteDB_Load(object sender, EventArgs e)
	{
		base.WindowState = FormWindowState.Maximized;
		LoadDisallowedRanges();
		LoadPeriodDatas();
		UpdatePeriodDatas();
		massDisallowedControl1.disallowedRangeChanged += DisallowedRangeChanged;
		ApplyResources();
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("FormAnalyteDB.Title.Text");
		colAbundance.HeaderText = Lang.Txt("FormAnalyteDB.Columns.Abundance.Text");
		colSelect.HeaderText = Lang.Txt("FormAnalyteDB.Columns.Selcted.Text");
		colDefault.HeaderText = Lang.Txt("FormAnalyteDB.Columns.Default.Text");
		colMass.HeaderText = Lang.Txt("FormAnalyteDB.Columns.Mass.Text");
		colSymbol.HeaderText = Lang.Txt("FormAnalyteDB.Columns.Symbol.Text");
		colEquation.HeaderText = Lang.Txt("FormAnalyteDB.Columns.CalibrationEqution.Text");
		colInterference.HeaderText = Lang.Txt("FormAnalyteDB.Columns.Interference.Text");
		tsmiSave.Text = Lang.Txt("FormExperiment.Save.Text");
		tsmiSaveAs.Text = Lang.Txt("FormExperiment.SaveAs.Text");
		fileToolStripMenuItem.Text = Lang.Txt("iMass.Menu.File.Text");
	}

	private void dgvIsotopes_CellValueChanged(object sender, DataGridViewCellEventArgs e)
	{
		if (e.ColumnIndex > -1 && e.RowIndex > -1)
		{
			string name = dgvIsotopes.Columns[e.ColumnIndex].Name;
			string text = name;
			if (text == "colSelect" || text == "colDefault")
			{
				db.SaveAnalyteIsotope(selectIsotopes[e.RowIndex]);
				UpdateIsotopeBox();
			}
		}
	}

	private void AddIsotope(double mass, double abundance)
	{
		AnalyteIsotope isotope = new AnalyteIsotope
		{
			mass = mass,
			abundance = abundance,
			symbol = (int)mass + currentAtom,
			atomicSymbol = currentAtom,
			atomicNum = -1,
			interferences = db.GetInterferenceByMass(mass),
			isotopeId = selectIsotopes.Count
		};
		if (db.SaveAnalyteIsotope(isotope))
		{
			selectIsotopes.Add(isotope);
			ReBindDatas();
			UpdateIsotopeBox();
		}
		else
		{
			Log.InsertLog(Lang.Txt("FormAnalyteDB.MessageBox.Caption.Text"), Lang.Txt("FormAnalyteDB.DataBase.AddIsotopesFailure.Text"), db.LastException.Message, Severity.Error);
		}
	}

	private void SetupDataGridViewRow(int index, AnalyteIsotope isotope, string equation = "")
	{
		dgvIsotopes.Rows[index].Cells["colIsotopeID"].Value = isotope.id;
		dgvIsotopes.Rows[index].Cells["colSelect"].Value = false;
		dgvIsotopes.Rows[index].Cells["colSymbol"].Value = isotope.symbol;
		dgvIsotopes.Rows[index].Cells["colMass"].Value = isotope.mass.ToString("F3");
		dgvIsotopes.Rows[index].Cells["colAbundance"].Value = isotope.abundance.ToString("F3");
		dgvIsotopes.Rows[index].Cells["colEquation"].Value = equation;
		dgvIsotopes.Rows[index].Cells["colInterference"].Value = isotope.interferences;
	}

	private void DeleteIsotope()
	{
		if (dgvIsotopes.SelectedCells != null && dgvIsotopes.SelectedCells.Count > 0)
		{
			int rowIndex = dgvIsotopes.SelectedCells[0].RowIndex;
			int id = selectIsotopes[rowIndex].id;
			if (db.DeleteAnalyteIsotope(id))
			{
				selectIsotopes.RemoveAt(rowIndex);
				ReBindDatas();
				UpdateIsotopeBox();
			}
			else
			{
				Log.InsertLog(Lang.Txt("FormAnalyteDB.DataBase.Text"), Lang.Txt("FormAnalyteDB.DataBase.DeleteIsotopesFailure.Text"), db.LastException.Message, Severity.Error);
			}
		}
	}

	private void UpdateIsotopeBox()
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		if (atomEventArgs == null || currentAtomicbox == null)
		{
			return;
		}
		object obj = currentAtomicbox;
		IsotopeBox isotopeBox = (IsotopeBox)((obj is IsotopeBox) ? obj : null);
		isotopeBox.IsValid = dgvIsotopes.Rows.Count != 0;
		isotopeBox.Status.SelectStatus.Clear();
		foreach (AnalyteIsotope isotope in selectIsotopes)
		{
			float mass = (float)isotope.mass;
			bool select = isotope.userSelection;
			int status = IsotopeBox.GetStatus(CheckDisallowedMass(mass), select);
			isotopeBox.Status.SelectStatus.Add(new MassStatus
			{
				Mass = mass,
				Status = status
			});
		}
		((Control)(object)isotopeBox).Refresh();
	}

	private bool CheckDisallowedMass(float mass)
	{
		foreach (PointF pt in massDisallowedControl1.DisallowedRange)
		{
			if (pt.X <= mass && pt.Y >= mass)
			{
				return true;
			}
		}
		return false;
	}

	private void dgvIsotopes_CurrentCellDirtyStateChanged(object sender, EventArgs e)
	{
		if (dgvIsotopes.IsCurrentCellDirty)
		{
			dgvIsotopes.CommitEdit(DataGridViewDataErrorContexts.Commit);
		}
	}

	private void dgvIsotopes_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.ColumnIndex < 0 || e.RowIndex < 0)
		{
			return;
		}
		string name = dgvIsotopes.Columns[e.ColumnIndex].Name;
		string text = name;
		if (text == "colEquation")
		{
			AnalyteIsotope isotope = selectIsotopes[e.RowIndex];
			FormEquation form = new FormEquation(db, isotope);
			if (form.ShowDialog() == DialogResult.OK)
			{
				db.SaveAnalyteIsotope(isotope);
				dgvIsotopes.Refresh();
			}
		}
	}

	public void BegineditDatagridView()
	{
		dgvIsotopes.CurrentCellDirtyStateChanged -= dgvIsotopes_CurrentCellDirtyStateChanged;
		dgvIsotopes.CellValueChanged -= dgvIsotopes_CellValueChanged;
		dgvIsotopes.CellDoubleClick -= dgvIsotopes_CellDoubleClick;
	}

	public void EndeditDatagridview()
	{
		dgvIsotopes.CurrentCellDirtyStateChanged += dgvIsotopes_CurrentCellDirtyStateChanged;
		dgvIsotopes.CellValueChanged += dgvIsotopes_CellValueChanged;
		dgvIsotopes.CellDoubleClick += dgvIsotopes_CellDoubleClick;
	}

	private void InitIonsTree()
	{
		polyNode = treeViewIons.Nodes.Add(Lang.Txt("FormAnalyteDB.Ions.Poly.Text"));
		matrixNode = treeViewIons.Nodes.Add(Lang.Txt("FormAnalyteDB.Ions.Matrix.Text"));
		addPolyNode = polyNode.Nodes.Add(Lang.Txt("FormAnalyteDB.Ions.AddPoly.Text"));
		addMatrixNode = matrixNode.Nodes.Add(Lang.Txt("FormAnalyteDB.Ions.AddMatrix.Text"));
		treeViewIons.NodeMouseClick += treeViewIons_NodeMouseClick;
		treeViewIons.BeforeExpand += treeViewIons_BeforeExpand;
	}

	private void treeViewIons_BeforeExpand(object sender, TreeViewCancelEventArgs e)
	{
		if (!hasLoadIons)
		{
			hasLoadIons = true;
			LoadPolyIons();
			LoadMatrixIons();
		}
	}

	private void LoadPolyIons()
	{
		IList<PolyIons> polyions = db.GetPolyIons();
		if (polyions == null)
		{
			return;
		}
		foreach (PolyIons ion in polyions)
		{
			polyNode.Nodes.Add(ion.atomic);
		}
	}

	private void LoadMatrixIons()
	{
		IList<MatrixIons> matrixIons = db.GetMatrixIons();
		if (matrixIons == null)
		{
			return;
		}
		foreach (MatrixIons ion in matrixIons)
		{
			matrixNode.Nodes.Add(ion.atomic);
		}
	}

	private void treeViewIons_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		if (e.Button != MouseButtons.Left)
		{
			return;
		}
		if (e.Node == addPolyNode)
		{
			treeViewIons.Enabled = false;
			dgvIsotopes.Enabled = false;
			massDisallowedControl1.Enabled = false;
			periodicTable1.AtomClick -= new DelegateAtomClick(periodicTable_AtomClick);
			FormPolyIon formIons = new FormPolyIon();
			periodicTable1.AtomClick += new DelegateAtomClick(formIons.periodicTable_AtomClick);
			formIons.FormClosed += delegate
			{
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Expected O, but got Unknown
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				if (formIons.DialogResult == DialogResult.OK)
				{
					AddPolyIons(formIons.Atomics.ToArray(), formIons.IsM2);
				}
				periodicTable1.AtomClick -= new DelegateAtomClick(formIons.periodicTable_AtomClick);
				periodicTable1.AtomClick += new DelegateAtomClick(periodicTable_AtomClick);
				treeViewIons.Enabled = true;
				dgvIsotopes.Enabled = true;
				massDisallowedControl1.Enabled = true;
			};
			formIons.Show();
		}
		else if (e.Node != addMatrixNode && (polyNode.Nodes.Contains(e.Node) || matrixNode.Nodes.Contains(e.Node)))
		{
			string atom = e.Node.Text;
			PolyIonsSelected(atom);
		}
	}

	private void PolyIonsSelected(string atom)
	{
		currentAtomicbox = null;
		atomEventArgs = null;
		currentAtom = atom;
		AddIsotope2Dgw(currentAtom);
	}

	private void AddPolyIons(string[] atoms, bool isM2)
	{
		string newAtom = "";
		if (isM2 && atoms.Length == 1)
		{
			string atom = atoms[0];
			newAtom = atom + "++";
			IList<AnalyteIsotope> tmpIsotopes = db.GetAnalyteIsotopesByAtomic(newAtom);
			if (tmpIsotopes != null && tmpIsotopes.Count > 0)
			{
				MessageBox.Show(Lang.Txt("AnalyteDb.Text8"));
			}
			else
			{
				IList<AnalyteIsotope> isotopes = db.GetAnalyteIsotopesByAtomic(atom);
				List<AnalyteIsotope> newIsotopes = new List<AnalyteIsotope>();
				foreach (AnalyteIsotope isotope2 in isotopes)
				{
					AnalyteIsotope newIsotope = new AnalyteIsotope();
					newIsotope.abundance = isotope2.abundance;
					newIsotope.analyteType = 2;
					newIsotope.atomicNum = isotope2.atomicNum;
					newIsotope.atomicSymbol = isotope2.atomicSymbol + "++";
					newIsotope.defaultSelection = isotope2.defaultSelection;
					newIsotope.intMass = (int)(isotope2.mass / 2.0);
					newIsotope.mass = isotope2.mass / 2.0;
					newIsotope.symbol = isotope2.symbol + "++";
					newIsotope.userSelection = isotope2.userSelection;
					newIsotope.withInterference = false;
					newIsotopes.Add(newIsotope);
				}
				newIsotopes.ForEach(delegate(AnalyteIsotope isotope)
				{
					isotope.mass = (double)(int)(isotope.mass * 10000.0) / 10000.0;
					isotope.abundance = (int)(isotope.abundance * 10000.0 / 10000.0);
				});
				newIsotopes.Sort((AnalyteIsotope i1, AnalyteIsotope i2) => i1.mass.CompareTo(i2.mass));
				db.SaveAnalyteIsotopes(newIsotopes);
			}
		}
		else
		{
			List<AtomInfos> atomInfos = new List<AtomInfos>();
			foreach (string atom2 in atoms)
			{
				AtomInfos info = db.GetAtomInfo(atom2);
				if (info == null)
				{
					MessageBox.Show("Error occurs.");
					return;
				}
				atomInfos.Add(info);
			}
			atomInfos.Sort((AtomInfos a1, AtomInfos a2) => a1.AtomNum.CompareTo(a2.AtomNum));
			StringBuilder sb = new StringBuilder();
			foreach (AtomInfos info2 in atomInfos)
			{
				sb.Append(info2.AtomSymbol);
				sb.Append(" ");
			}
			newAtom = sb.ToString();
			IList<AnalyteIsotope> tmpIsotopes2 = db.GetAnalyteIsotopesByAtomic(newAtom);
			if (tmpIsotopes2 != null && tmpIsotopes2.Count > 0)
			{
				MessageBox.Show(Lang.Txt("AnalyteDb.Text8"));
			}
			else
			{
				AnalyteIsotope[][] selectIsotopes = new AnalyteIsotope[atomInfos.Count][];
				for (int k = 0; k < atomInfos.Count; k++)
				{
					selectIsotopes[k] = db.GetAnalyteIsotopesByAtomic(atomInfos[k].AtomSymbol).ToArray();
				}
				AnalyteIsotope[] newIsotopes2 = selectIsotopes[0];
				for (int j = 1; j < atomInfos.Count; j++)
				{
					newIsotopes2 = MultiCombine(newIsotopes2, selectIsotopes[j]);
				}
				List<AnalyteIsotope> addIsotopes = new List<AnalyteIsotope>();
				AnalyteIsotope[] array = newIsotopes2;
				foreach (AnalyteIsotope isotope3 in array)
				{
					if (!addIsotopes.Exists((AnalyteIsotope t) => t.intMass == isotope3.intMass))
					{
						isotope3.analyteType = 3;
						isotope3.atomicNum = 0;
						isotope3.atomicSymbol = newAtom;
						isotope3.defaultSelection = false;
						isotope3.isotopeId = addIsotopes.Count;
						isotope3.symbol = isotope3.intMass + newAtom;
						isotope3.interferences = db.GetInterferenceByMass(isotope3.intMass);
						addIsotopes.Add(isotope3);
					}
					else
					{
						AnalyteIsotope oldIsotope = addIsotopes.Find((AnalyteIsotope t) => t.intMass == isotope3.intMass);
						oldIsotope.mass = (oldIsotope.abundance * oldIsotope.mass + isotope3.abundance * isotope3.mass) / (oldIsotope.abundance + isotope3.abundance);
						oldIsotope.abundance += isotope3.abundance;
					}
				}
				addIsotopes.Sort((AnalyteIsotope i1, AnalyteIsotope i2) => i1.mass.CompareTo(i2.mass));
				addIsotopes.ForEach(delegate(AnalyteIsotope isotope)
				{
					isotope.mass = (double)(int)(isotope.mass * 10000.0) / 10000.0;
					isotope.abundance = (double)(int)(isotope.abundance * 10000.0) / 10000.0;
				});
				db.SaveAnalyteIsotopes(addIsotopes);
			}
		}
		treeViewIons.Nodes[0].Nodes.Add(newAtom);
		PolyIonsSelected(newAtom);
	}

	private AnalyteIsotope[] MultiCombine(AnalyteIsotope[] isotopes1, AnalyteIsotope[] isotopes2)
	{
		List<AnalyteIsotope> isotopes3 = new List<AnalyteIsotope>();
		foreach (AnalyteIsotope isotope2 in isotopes1)
		{
			foreach (AnalyteIsotope isotope3 in isotopes2)
			{
				AnalyteIsotope isotope = new AnalyteIsotope();
				isotope.mass = isotope2.mass + isotope3.mass;
				isotope.abundance = isotope2.abundance * isotope3.abundance / 100.0;
				isotope.intMass = (int)(isotope.mass + 0.5);
				isotopes3.Add(isotope);
			}
		}
		return isotopes3.ToArray();
	}

	private void tsmiSave_Click(object sender, EventArgs e)
	{
		if (!isSaved)
		{
			if (SaveDB() == 1)
			{
				isSaved = true;
			}
		}
		else
		{
			WritetoLocal();
		}
	}

	private void tsmiSaveAs_Click(object sender, EventArgs e)
	{
		if (SaveDB(saveAs: true) == 1)
		{
			isSaved = true;
		}
	}

	private void periodicTable1_MouseDown(object sender, MouseEventArgs e)
	{
	}

	private void LoadDisallowedRanges()
	{
		IList<ExclusionRegion> exclusionRegion = db.GetExclusionRegions();
		if (exclusionRegion == null)
		{
			return;
		}
		massDisallowedControl1.DisallowedRange.Clear();
		foreach (ExclusionRegion region in exclusionRegion)
		{
			massDisallowedControl1.DisallowedRange.Add(new PointF((float)region.start, (float)region.end));
		}
		massDisallowedControl1.SelectFirst();
	}

	private void SaveDisallowedRanges()
	{
		if (db.DeleteAllExclusionRegion())
		{
			List<ExclusionRegion> regions = new List<ExclusionRegion>();
			foreach (PointF pt in massDisallowedControl1.DisallowedRange)
			{
				regions.Add(new ExclusionRegion
				{
					start = pt.X,
					end = pt.Y
				});
			}
			if (regions.Count > 0)
			{
				db.SaveExclusionRegions(regions);
			}
		}
		else
		{
			MessageBox.Show("delete error");
		}
	}

	private void LoadPeriodDatas()
	{
		IList<AnalyteIsotope> isotopes = db.GetAnalyteIsotopes();
		foreach (AnalyteIsotope isotope in isotopes)
		{
			periodicTable1.LoadStatus(isotope.atomicSymbol, isotope.isotopeId, isotope.mass, isotope.userSelection);
		}
		periodicTable1.CheckValid();
	}

	private void UpdatePeriodDatas()
	{
		periodicTable1.UpdateStatus(massDisallowedControl1.DisallowedRange);
		Invoke((EventHandler)delegate
		{
			((Control)(object)periodicTable1).Refresh();
		});
	}

	private void DisallowedRangeChanged(object sender, EventArgs e)
	{
		UpdatePeriodDatas();
	}

	private void dgvIsotopes_MouseDown(object sender, MouseEventArgs e)
	{
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
		this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
		this.dgvIsotopes = new System.Windows.Forms.DataGridView();
		this.colSelect = new System.Windows.Forms.DataGridViewCheckBoxColumn();
		this.colDefault = new System.Windows.Forms.DataGridViewCheckBoxColumn();
		this.colSymbol = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colMass = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colAbundance = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colEquation = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.colInterference = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
		this.massDisallowedControl1 = new ICP_MS.Plugin.AnalyteDb.MassDisallowedControl();
		this.panel1 = new System.Windows.Forms.Panel();
		this.periodicTable1 = new PeriodicTable();
		this.treeViewIons = new System.Windows.Forms.TreeView();
		this.menuStripAnalyteDB = new System.Windows.Forms.MenuStrip();
		this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
		this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
		this.tsmiSave = new System.Windows.Forms.ToolStripMenuItem();
		this.tsmiSaveAs = new System.Windows.Forms.ToolStripMenuItem();
		this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.tableLayoutPanel1.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgvIsotopes).BeginInit();
		this.tableLayoutPanel2.SuspendLayout();
		this.panel1.SuspendLayout();
		this.menuStripAnalyteDB.SuspendLayout();
		base.SuspendLayout();
		this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetPartial;
		this.tableLayoutPanel1.ColumnCount = 2;
		this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 189f));
		this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100f));
		this.tableLayoutPanel1.Controls.Add(this.dgvIsotopes, 1, 0);
		this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 1);
		this.tableLayoutPanel1.Controls.Add(this.treeViewIons, 0, 0);
		this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
		this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
		this.tableLayoutPanel1.Name = "tableLayoutPanel1";
		this.tableLayoutPanel1.RowCount = 2;
		this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100f));
		this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 406f));
		this.tableLayoutPanel1.Size = new System.Drawing.Size(893, 607);
		this.tableLayoutPanel1.TabIndex = 0;
		this.dgvIsotopes.AllowUserToAddRows = false;
		this.dgvIsotopes.AllowUserToDeleteRows = false;
		this.dgvIsotopes.AllowUserToResizeRows = false;
		this.dgvIsotopes.BackgroundColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
		dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
		dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
		this.dgvIsotopes.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
		this.dgvIsotopes.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgvIsotopes.Columns.AddRange(this.colSelect, this.colDefault, this.colSymbol, this.colMass, this.colAbundance, this.colEquation, this.colInterference);
		dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
		dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
		dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
		dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
		this.dgvIsotopes.DefaultCellStyle = dataGridViewCellStyle2;
		this.dgvIsotopes.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dgvIsotopes.Location = new System.Drawing.Point(198, 6);
		this.dgvIsotopes.MultiSelect = false;
		this.dgvIsotopes.Name = "dgvIsotopes";
		this.dgvIsotopes.RowTemplate.Height = 23;
		this.dgvIsotopes.Size = new System.Drawing.Size(689, 186);
		this.dgvIsotopes.TabIndex = 2;
		this.dgvIsotopes.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgvIsotopes_CellDoubleClick);
		this.dgvIsotopes.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(dgvIsotopes_CellValueChanged);
		this.dgvIsotopes.CurrentCellDirtyStateChanged += new System.EventHandler(dgvIsotopes_CurrentCellDirtyStateChanged);
		this.dgvIsotopes.MouseDown += new System.Windows.Forms.MouseEventHandler(dgvIsotopes_MouseDown);
		this.colSelect.DataPropertyName = "userSelection";
		this.colSelect.FillWeight = 20f;
		this.colSelect.HeaderText = "New.Select.Text";
		this.colSelect.Name = "colSelect";
		this.colSelect.Resizable = System.Windows.Forms.DataGridViewTriState.True;
		this.colSelect.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
		this.colSelect.Width = 60;
		this.colDefault.DataPropertyName = "defaultSelection";
		this.colDefault.FillWeight = 20f;
		this.colDefault.HeaderText = "New.DefaultOption.Text";
		this.colDefault.Name = "colDefault";
		this.colDefault.Resizable = System.Windows.Forms.DataGridViewTriState.True;
		this.colDefault.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
		this.colDefault.Width = 80;
		this.colSymbol.DataPropertyName = "symbol";
		this.colSymbol.FillWeight = 20f;
		this.colSymbol.HeaderText = "New.ColSymbol.Text";
		this.colSymbol.Name = "colSymbol";
		this.colSymbol.ReadOnly = true;
		this.colSymbol.Width = 80;
		this.colMass.DataPropertyName = "mass";
		this.colMass.FillWeight = 20f;
		this.colMass.HeaderText = "New.ColMass.Text";
		this.colMass.Name = "colMass";
		this.colMass.ReadOnly = true;
		this.colMass.Width = 80;
		this.colAbundance.DataPropertyName = "abundance";
		this.colAbundance.FillWeight = 20f;
		this.colAbundance.HeaderText = "New.ColAbundance.Text";
		this.colAbundance.Name = "colAbundance";
		this.colAbundance.ReadOnly = true;
		this.colAbundance.Width = 60;
		this.colEquation.DataPropertyName = "equation";
		this.colEquation.FillWeight = 20f;
		this.colEquation.HeaderText = "New.ColEquation.Text";
		this.colEquation.Name = "colEquation";
		this.colEquation.ReadOnly = true;
		this.colInterference.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.colInterference.DataPropertyName = "interferences";
		this.colInterference.HeaderText = "New.ColInterference.Text";
		this.colInterference.Name = "colInterference";
		this.colInterference.ReadOnly = true;
		this.tableLayoutPanel2.ColumnCount = 3;
		this.tableLayoutPanel1.SetColumnSpan(this.tableLayoutPanel2, 2);
		this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50f));
		this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 720f));
		this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50f));
		this.tableLayoutPanel2.Controls.Add(this.massDisallowedControl1, 0, 0);
		this.tableLayoutPanel2.Controls.Add(this.panel1, 1, 1);
		this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
		this.tableLayoutPanel2.Location = new System.Drawing.Point(6, 201);
		this.tableLayoutPanel2.Name = "tableLayoutPanel2";
		this.tableLayoutPanel2.RowCount = 2;
		this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.36314f));
		this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 85.63686f));
		this.tableLayoutPanel2.Size = new System.Drawing.Size(881, 400);
		this.tableLayoutPanel2.TabIndex = 100;
		this.tableLayoutPanel2.SetColumnSpan(this.massDisallowedControl1, 3);
		this.massDisallowedControl1.Dock = System.Windows.Forms.DockStyle.Fill;
		this.massDisallowedControl1.Location = new System.Drawing.Point(3, 3);
		this.massDisallowedControl1.MinimumSize = new System.Drawing.Size(300, 32);
		this.massDisallowedControl1.Name = "massDisallowedControl1";
		this.massDisallowedControl1.Size = new System.Drawing.Size(875, 51);
		this.massDisallowedControl1.TabIndex = 0;
		this.panel1.Controls.Add((System.Windows.Forms.Control)(object)this.periodicTable1);
		this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
		this.panel1.Location = new System.Drawing.Point(83, 60);
		this.panel1.Name = "panel1";
		this.panel1.Size = new System.Drawing.Size(714, 337);
		this.panel1.TabIndex = 1;
		((System.Windows.Forms.Control)(object)this.periodicTable1).Location = new System.Drawing.Point(3, 3);
		((System.Windows.Forms.Control)(object)this.periodicTable1).Name = "periodicTable1";
		((System.Windows.Forms.Control)(object)this.periodicTable1).Size = new System.Drawing.Size(720, 254);
		((System.Windows.Forms.Control)(object)this.periodicTable1).TabIndex = 0;
		((System.Windows.Forms.Control)(object)this.periodicTable1).MouseDown += new System.Windows.Forms.MouseEventHandler(periodicTable1_MouseDown);
		this.treeViewIons.Dock = System.Windows.Forms.DockStyle.Fill;
		this.treeViewIons.Location = new System.Drawing.Point(6, 6);
		this.treeViewIons.Name = "treeViewIons";
		this.treeViewIons.Size = new System.Drawing.Size(183, 186);
		this.treeViewIons.TabIndex = 1;
		this.menuStripAnalyteDB.ImageScalingSize = new System.Drawing.Size(20, 20);
		this.menuStripAnalyteDB.Items.AddRange(new System.Windows.Forms.ToolStripItem[1] { this.fileToolStripMenuItem });
		this.menuStripAnalyteDB.Location = new System.Drawing.Point(0, 0);
		this.menuStripAnalyteDB.MdiWindowListItem = this.fileToolStripMenuItem;
		this.menuStripAnalyteDB.Name = "menuStripAnalyteDB";
		this.menuStripAnalyteDB.Size = new System.Drawing.Size(893, 25);
		this.menuStripAnalyteDB.TabIndex = 1;
		this.menuStripAnalyteDB.Text = "menuStrip1";
		this.menuStripAnalyteDB.Visible = false;
		this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[3] { this.toolStripSeparator4, this.tsmiSave, this.tsmiSaveAs });
		this.fileToolStripMenuItem.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
		this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
		this.fileToolStripMenuItem.Size = new System.Drawing.Size(58, 21);
		this.fileToolStripMenuItem.Text = "文件(&F)";
		this.toolStripSeparator4.Name = "toolStripSeparator4";
		this.toolStripSeparator4.Size = new System.Drawing.Size(181, 6);
		this.tsmiSave.Image = ICP_MS.Plugin.AnalyteDb.Properties.Resources.Save;
		this.tsmiSave.Name = "tsmiSave";
		this.tsmiSave.Size = new System.Drawing.Size(184, 26);
		this.tsmiSave.Text = "保存";
		this.tsmiSave.Click += new System.EventHandler(tsmiSave_Click);
		this.tsmiSaveAs.Name = "tsmiSaveAs";
		this.tsmiSaveAs.Size = new System.Drawing.Size(184, 26);
		this.tsmiSaveAs.Text = "另存为...";
		this.tsmiSaveAs.Click += new System.EventHandler(tsmiSaveAs_Click);
		this.dataGridViewTextBoxColumn1.DataPropertyName = "symbol";
		this.dataGridViewTextBoxColumn1.FillWeight = 20f;
		this.dataGridViewTextBoxColumn1.HeaderText = "选择";
		this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
		this.dataGridViewTextBoxColumn1.ReadOnly = true;
		this.dataGridViewTextBoxColumn1.Visible = false;
		this.dataGridViewTextBoxColumn1.Width = 60;
		this.dataGridViewTextBoxColumn2.DataPropertyName = "mass";
		this.dataGridViewTextBoxColumn2.FillWeight = 20f;
		this.dataGridViewTextBoxColumn2.HeaderText = "默认项";
		this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
		this.dataGridViewTextBoxColumn2.ReadOnly = true;
		this.dataGridViewTextBoxColumn2.Width = 80;
		this.dataGridViewTextBoxColumn3.DataPropertyName = "abundance";
		this.dataGridViewTextBoxColumn3.FillWeight = 20f;
		this.dataGridViewTextBoxColumn3.HeaderText = "符号";
		this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
		this.dataGridViewTextBoxColumn3.ReadOnly = true;
		this.dataGridViewTextBoxColumn3.Width = 80;
		this.dataGridViewTextBoxColumn4.DataPropertyName = "equation";
		this.dataGridViewTextBoxColumn4.FillWeight = 20f;
		this.dataGridViewTextBoxColumn4.HeaderText = "质量数";
		this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
		this.dataGridViewTextBoxColumn4.ReadOnly = true;
		this.dataGridViewTextBoxColumn4.Width = 80;
		this.dataGridViewTextBoxColumn5.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn5.DataPropertyName = "interferences";
		this.dataGridViewTextBoxColumn5.FillWeight = 20f;
		this.dataGridViewTextBoxColumn5.HeaderText = "丰度";
		this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
		this.dataGridViewTextBoxColumn5.ReadOnly = true;
		this.dataGridViewTextBoxColumn6.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
		this.dataGridViewTextBoxColumn6.FillWeight = 20f;
		this.dataGridViewTextBoxColumn6.HeaderText = "校正方程";
		this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
		this.dataGridViewTextBoxColumn6.ReadOnly = true;
		this.dataGridViewTextBoxColumn7.FillWeight = 20f;
		this.dataGridViewTextBoxColumn7.HeaderText = "干扰项";
		this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
		this.dataGridViewTextBoxColumn7.ReadOnly = true;
		this.dataGridViewTextBoxColumn7.Width = 150;
		this.dataGridViewTextBoxColumn8.HeaderText = "干扰项";
		this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8";
		this.dataGridViewTextBoxColumn8.ReadOnly = true;
		this.dataGridViewTextBoxColumn8.Width = 150;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(893, 607);
		base.Controls.Add(this.tableLayoutPanel1);
		base.Controls.Add(this.menuStripAnalyteDB);
		base.MainMenuStrip = this.menuStripAnalyteDB;
		base.Name = "FormAnalyteDB";
		base.ShowIcon = false;
		this.Text = "同位素数据库";
		base.WindowState = System.Windows.Forms.FormWindowState.Maximized;
		base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormAnalyteDB_FormClosing);
		base.Load += new System.EventHandler(FormAnalyteDB_Load);
		this.tableLayoutPanel1.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.dgvIsotopes).EndInit();
		this.tableLayoutPanel2.ResumeLayout(false);
		this.panel1.ResumeLayout(false);
		this.menuStripAnalyteDB.ResumeLayout(false);
		this.menuStripAnalyteDB.PerformLayout();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
